package hehe.web;

import hehe.core.base.ContextApplication;
import hehe.core.base.ContextLoader;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Servlet 容器监听器类
 *<B>说明：</B>
 *<pre>
 * 实现功能:
 * 解析bean.xml配置,hehej容器准备
 *</pre>
 *<B>示例：</B>
 *<pre>
 *  略
 *</pre>
 *<B>日志：</B>
 *<pre>
 *  略
 *</pre>
 *<B>注意事项：</B>
 *<pre>
 *  略
 *</pre>
 */
public class ContextLoaderListener extends ContextLoader implements ServletContextListener
{

    protected ContextApplication contextApplication;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent)
    {
        // 加载核心组件
        this.loadComponents();

        // 加载xml配置文件
        ServletContext ServletContext = servletContextEvent.getServletContext();
        String configFilePath = ServletContext.getInitParameter(CONTEXT_ID_PARAM);
        configFilePath = ServletContext.getRealPath(configFilePath);


        this.contextApplication = new ContextApplication(configFilePath);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        this.contextApplication.destroy();
    }

}
